#include <iostream>
#include <queue>
using namespace std;


struct rel{
	int a,b;
	long long c;
	bool operator < (const rel x)const{
		return c<x.c;
	}
};


int find(int *f,int *v,int x){
	if(f[x] == x) return x;
	f[x] = find(f,v,f[x]);
	v[x] = (v[f[x]]+v[x])%2;
	return f[x];
}


int main(){
	int n,m;
	long long ans=0;
	cin>>n>>m;
	int f[n],v[n]={0};
	rel relation[m];
	for(int i=0;i<n;i++)
		f[i] = i;
	priority_queue<rel> q;
	for(int i=0;i<m;i++){
		cin>>relation[i].a>>relation[i].b>>relation[i].c;
		relation[i].a--;relation[i].b--;
		q.push(relation[i]);
	}
	for(int i=0;i<m;i++){
		rel l;
		l = q.top();
		int f1=find(f,v,l.a),f2=find(f,v,l.b);
		if(f1 != f2){
			v[f1] = (v[l.a]+v[l.b]+1)%2;
			f[f1] = f[f2];
		}
		else{
			if((v[l.a]+v[l.b])%2 == 0){
				ans = l.c;
				break;
			}
		}
		q.pop();
	}
	cout<<ans;
	return 0;
}
